<?php

/**
 * This is the model class for table "yii_przychodnia.lekarz".
 *
 * The followings are the available columns in table 'yii_przychodnia.lekarz':
 * @property integer $idLekarz
 * @property string $Imie
 * @property string $Nazwisko
 * @property string $Tytul
 * @property string $Telefon
 *
 * The followings are the available model relations:
 * @property Czaspracy[] $czaspracys
 * @property Wizyta[] $wizytas
 */
class Lekarz extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Lekarz the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'yii_przychodnia.lekarz';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('Imie, Nazwisko', 'required'),
			array('Imie, Telefon', 'length', 'max'=>15),
			array('Nazwisko, Tytul', 'length', 'max'=>30),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('idLekarz, Imie, Nazwisko, Tytul, Telefon', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'czaspracy' => array(self::HAS_MANY, 'Czaspracy', 'idLekarz'),
			'wizyta' => array(self::HAS_MANY, 'Wizyta', 'idLekarz'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'idLekarz' => 'ID',
			'Imie' => 'Imię',
			'Nazwisko' => 'Nazwisko',
			'Tytul' => 'Tytuł',
			'Telefon' => 'Telefon',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('idLekarz',$this->idLekarz);
		$criteria->compare('Imie',$this->Imie,true);
		$criteria->compare('Nazwisko',$this->Nazwisko,true);
		$criteria->compare('Tytul',$this->Tytul,true);
		$criteria->compare('Telefon',$this->Telefon,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}

        public function getFullname()
        {
                return $this->Nazwisko.' '.$this->Imie.', '.$this->Tytul;
        }
}